package com.zjbbkj.baibai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjbbkj.baibai.common.utils.idWork.IdWorker;
import com.zjbbkj.baibai.device.mapper.DeviceMapper;
import com.zjbbkj.baibai.device.service.DeviceService;
import com.zjbbkj.baibai.domain.device.Device;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author WanLi
 * @email wanli_work@163.com
 * @date 2021年08月26日 14:12
 */
@Slf4j
@Service("deviceService")
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {

    @Resource
    private DeviceMapper deviceMapper;

    @Resource
    private IdWorker idWorker;

    @Override
    public Device getDeviceByImeiId(String imeiid) {
        QueryWrapper<Device> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("device_imei",imeiid);
        return deviceMapper.selectOne(userQueryWrapper);
    }

    @Override
    public int insert(String IMEIID) {
        Device device = new Device();
        device.setDeviceId(String.valueOf(idWorker.nextId()));
        device.setDeviceImei(IMEIID);
        return deviceMapper.insert(device);
    }

    @Override
    public int update(Device device) {
        return deviceMapper.updateById(device);
    }

}
